//ECMAScript 2017
const obj = {
  foo: "value1",
  bar: "value2",
};

//1.Object.values() 返回对象中所有值的数组
console.log(Object.values(obj)); //[ 'value1', 'value2' ]

//2.Object.entries() 以数组的形式去返回对象中所有的键值对
for (const [key, value] of Object.entries(obj)) {
  console.log(key, value);
}
//foo value1
//bar value2
//Map构造函数需要的就是这样格式的数组，可以利用Object.entries()将对象转化成Map类型
console.log(new Map(Object.entries(obj))); //Map { 'foo' => 'value1', 'bar' => 'value2' }

//3.Object.getOwnPropertyDescriptors() 获取对象中属性的完整信息

const p1 = {
  firstName: "lei",
  lastName: "Wang",
  get fullName() {
    return this.firstName + " " + this.lastName;
  },
};
console.log(p1.fullName); //lei Wang
const p2 = Object.assign({}, p1);
p2.firstName = "lagou";
console.log(p2); //{ firstName: 'lagou', lastName: 'Wang', fullName: 'lei Wang' } 只是将fullName当成一个普通的属性

const descriptors = Object.getOwnPropertyDescriptors(p1);
console.log(descriptors);
const p3 = Object.defineProperties({}, descriptors);
p3.firstName = "lagou";
console.log(p3.fullName); //lagou Wang

//4.String.prototype.padStart / String.prototype.padEnd 指定字符转的长度，一自定义的标识填充
const books = {
  html: 3,
  css: 15,
  javascript: 128,
};
for (const [key, value] of Object.entries(books)) {
  console.log(`${key.padEnd(16, "-")}${value.toString().padStart(3, "0")}`);
}
// css-------------015
// html------------003
// javascript------128

//5.在函数的参数中添加尾逗号// function foo(bar, vaz,) {}
//[1,3,4,5,] 每行格式一致，方便调位置，新建元素直接添加即可，无需在原有元素后面添加逗号
